﻿// CBase1Dlg.cpp: 实现文件
//

#include "pch.h"
#include "CViewportController.h"
#include "CBase1Dlg.h"
#include "afxdialogex.h"
#include "resource.h"



// CBase1Dlg 对话框

IMPLEMENT_DYNAMIC(CBase1Dlg, CDialogEx)

CBase1Dlg::CBase1Dlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_BASE_1, pParent)
{

}

CBase1Dlg::~CBase1Dlg()
{
}

void CBase1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CBase1Dlg, CDialogEx)
	ON_WM_MOVE()
	ON_WM_NCLBUTTONDOWN()
	ON_WM_MOVING()
	ON_WM_NCLBUTTONUP()
	ON_WM_CLOSE()
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_RBUTTONUP()
	ON_COMMAND(ID_Linear0, &CBase1Dlg::OnLinear0)
	ON_COMMAND(ID_Linear5, &CBase1Dlg::OnLinear5)
	ON_COMMAND(ID_Linear10, &CBase1Dlg::OnLinear10)
	ON_COMMAND(ID_Linear2, &CBase1Dlg::OnLinear2)
END_MESSAGE_MAP()


// CBase1Dlg 消息处理程序


BOOL CBase1Dlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化

	this->MoveWindow(0, 0, 600, 600);

	m_bBtnDn = FALSE;
	bBD = FALSE;

	MousePos.x = 0;
	MousePos.y = 0;

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}


void CBase1Dlg::OnMove(int x, int y)
{
	CDialogEx::OnMove(x, y);
}


void CBase1Dlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
	m_bBtnDn = true;

	CDialogEx::OnNcLButtonDown(nHitTest, point);
}


void CBase1Dlg::OnMoving(UINT fwSide, LPRECT pRect)
{
	CDialogEx::OnMoving(fwSide, pRect);

	if (m_bBtnDn)
	{
		m_pViewController->ResetWindowsPos();
	}
}


void CBase1Dlg::OnNcLButtonUp(UINT nHitTest, CPoint point)
{
	m_bBtnDn = false;

	CDialogEx::OnNcLButtonUp(nHitTest, point);
}


void CBase1Dlg::OnClose()
{
	m_pViewController->OnMainDialogClose();

	CDialogEx::OnClose();
}


void CBase1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	bBD = TRUE;
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	CDialogEx::OnLButtonDown(nFlags, point);
}


void CBase1Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
	if (bBD)
	{
		m_pViewController->MainToZoom(point);
	}

	CDialogEx::OnMouseMove(nFlags, point);
}


void CBase1Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
	bBD = FALSE;

	CDialogEx::OnLButtonUp(nFlags, point);
}


void CBase1Dlg::OnRButtonUp(UINT nFlags, CPoint point)
{
	CMenu menu; //定义下面要用到的cmenu对象
	menu.LoadMenu(IDR_MENU4); //装载自定义的右键菜单 
	CMenu *pPopup = menu.GetSubMenu(0); //获取第一个弹出菜单，所以第一个菜单必须有子菜单

	CPoint point1;//定义一个用于确定光标位置的位置 
	GetCursorPos(&point1);//获取当前光标的位置，以便使得菜单可以跟随光标 

	pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point1.x, point1.y, this);//在指定位置显示弹出菜单

	CDialogEx::OnRButtonUp(nFlags, point);
}


void CBase1Dlg::OnLinear0()
{
	m_pViewController->iPercent = 0;
	m_pViewController->LinearStretch(0);
	m_pViewController->DrawBaseImage();
}


void CBase1Dlg::OnLinear5()
{
	m_pViewController->iPercent = 5;
	m_pViewController->LinearStretch(5);
	m_pViewController->DrawBaseImage();
}


void CBase1Dlg::OnLinear10()
{
	m_pViewController->iPercent = 10;
	m_pViewController->LinearStretch(10);
	m_pViewController->DrawBaseImage();
}


void CBase1Dlg::OnLinear2()
{
	m_pViewController->iPercent = 2;
	m_pViewController->LinearStretch(2);
	m_pViewController->DrawBaseImage();
}
